<template>
  <div class="hmi-table-toolbar" :class="{ compact }">
    <div class="hmi-table-toolbar__left">
      <slot name="left" />
    </div>
    <div class="hmi-table-toolbar__right">
      <slot name="right-extra" />
      <el-button
        v-if="showRefresh"
        type="info"
        :icon="Refresh"
        :loading="loading"
        @click="$emit('refresh')"
      >
        刷新
      </el-button>
      <el-button v-if="showExport" type="success" :icon="Download" @click="$emit('export')">
        导出
      </el-button>
    </div>
  </div>
  
</template>

<script setup lang="ts">
import { Refresh, Download } from "@element-plus/icons-vue";

interface Props {
  showRefresh?: boolean;
  showExport?: boolean;
  loading?: boolean;
  compact?: boolean; // 去背景/内边距的紧凑模式
}

withDefaults(defineProps<Props>(), {
  showRefresh: true,
  showExport: true,
  loading: false,
  compact: false,
});

defineEmits(["refresh", "export"]);
</script>

<style scoped lang="scss">
.hmi-table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 4px;

  &__left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
  }

  &__right {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  &.compact {
    background: transparent;
    padding: 0;
  }
}
</style>

